﻿using System.Data.Entity;
using Microsoft.Owin;
using Owin;
using PortalWeb.Business.Manager;
using PortalWeb.CMS.Business;
using PortalWeb.CMS.Core.IManager;
using PortalWeb.CMS.Dao;
using PortalWeb.Core.IManager;
using PortalWeb.Dao.Base;
using PortalWeb.Quartz.Dao;
using Quick.Common;
using Quick.PluginFramework;

[assembly: OwinStartupAttribute(typeof(PortalWeb.Startup))]
namespace PortalWeb
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            Quick.Common.Configuration.Create();

            ConfigureAutofac(app);

            ConfigureAuth(app);

            app.MapSignalR();

            Quick.Common.Configuration.Instance
                .UseCache()
                .UseMonitor()
                .UseLog4Net()
                .RegisterUnhandledExceptionHandler();

            Bootstrapper.Initialize();

            SetupResolveRules();
        }

        private void SetupResolveRules()
        {
            Quick.Common.Configuration.Instance.
                SetDefault<ApplicationIdentityDbContext, ApplicationIdentityDbContext>().
                SetDefault<IRoleGroupManager, RoleGroupManager>().
                SetDefault<IFunctionManager, FunctionManager>().

                SetDefault<DbContext, ApplicationDbContext>().
                SetDefault<IArticleManager, ArticleManager>().
                SetDefault<IAttachmentManager, AttachmentManager>().
                SetDefault<ICategoryManager, CategoryManager>().
                SetDefault<ICommonModelManager, CommonModelManager>().
                SetDefault<ICommentManager, CommentManager>().
                SetDefault<ISiteInfoManager, SiteInfoManager>().
                SetDefault<IJobsManager, JobsManager>().
                SetDefault<IProductManager, ProductManager>().

                SetDefault<QuartzDbContext, QuartzDbContext>();
        }
    }
}